package com.tomowork.entity;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.annotations.GeneratorType;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

@Entity
@Table(name = "dept")
public class Dept implements Serializable{
    private Integer deptno ;
    private String dname ;
    private String loc ;
    private Date createtime ;
    private Date updatetime ;


    @JsonIgnore//可以解决双向查询的循环调用问题
    private Set<Emp> emps = new HashSet<>();

    public Dept(){}
    public Dept(Integer deptno,String dname){
        this.deptno = deptno ;
        this.dname = dname ;
    }
    @Id
    @Column(unique = true,nullable = false)
//    @GeneratedValue(strategy = GenerationType.AUTO)
    public Integer getDeptno() {
        return deptno;
    }

    public void setDeptno(Integer deptno) {
        this.deptno = deptno;
    }
    @Column(name = "dname",unique = true)
    public String getDname() {
        return dname;
    }

    public void setDname(String dname) {
        this.dname = dname;
    }
    public String getLoc() {
        return loc;
    }
    public void setLoc(String loc) {
        this.loc = loc;
    }

    public Date getCreatetime() {
        return createtime;
    }

    public void setCreatetime(Date createtime) {
        this.createtime = createtime;
    }

    public Date getUpdatetime() {
        return updatetime;
    }

    public void setUpdatetime(Date updatetime) {
        this.updatetime = updatetime;
    }

    @OneToMany(cascade = {CascadeType.REMOVE},fetch = FetchType.LAZY)
    @JoinColumn(name="deptno")
    public Set<Emp> getEmps() {
        return emps;
    }

    public void setEmps(Set<Emp> emps) {
        this.emps = emps;
    }

}
